package com.ncp.servlet.registerlogin;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ncp.model.biz.registerlogin.RegisterBiz;
import com.ncp.model.biz.registerlogin.checkPwdBiz;
import com.ncp.model.entity.registerlogin.UserBasicBean;

public class checkPwdServlet extends HttpServlet {
	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String msg = "";
		HttpSession session = request.getSession(true);
		/***下面这个LoginName是在用户已经登录成功后。存在session中的用户信息***/
		String LoginName = "";
		if(session.getAttribute("LoginName")!=null)
			LoginName = session.getAttribute("LoginName").toString();
		 /***实现检测密码***/
		UserBasicBean UserBasic = new UserBasicBean();
		checkPwdBiz checkpwdbiz = new checkPwdBiz();
		String passWord = request.getParameter("userOldPwd");
		int checkpwdresult =checkpwdbiz.checkUserPsd(LoginName, passWord) ;
				/*** 是注册用户，则判断密码是否正确
				 * -1代表密码输入错误。
				 * 1代表密码输入正确。 ****/		
		if(checkpwdresult==1)
		{
			msg = "true";
		}
		else{
			msg = "false";
		}out.print(msg);
}
		/**
		* The doPost method of the servlet. <br>
		*
		* This method is called when a form has its tag value method equals to post.
		* 
		* @param request the request send by the client to the server
		* @param response the response send by the server to the client
		* @throws ServletException if an error occurred
		* @throws IOException if an error occurred
		*/
		public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
		}
		
}
